<?php

    include '..\Models.php';
        
    
    DbConnector::Connect();
        
    if(WebHelper::IsPostBack())
    {
        //echo("This is a postback");
        
        //echo($_POST["NAME"]);
        
        //$id = WebHelper::PostInt("ID");
        
        if($id == 0)
        {
            // Save the place
            
            $place = new Place();
        }
        else
        {
            $place = new Place($id);
        }
        
        
        $place->name = WebHelper::PostString("Name");
        $place->description = WebHelper::PostString("Description");
        $place->address = WebHelper::PostString("Address");
        $place->direction = WebHelper::PostString("Direction");
        $place->featured = WebHelper::PostString("featured");   
        $place->lat = WebHelper::PostFloat("Lat");
        $place->lon = WebHelper::PostFloat("Lon");
        $place->tag = WebHelper::PostString("Tag");
        $place->scoreTotal = WebHelper::PostInt("ScoreTotal");
        $place->scoreNumberPeople = WebHelper::PostInt("ScoreNumberPeople");
         
        //echo($place->name); 
          
        $place->Save();
            
        WebHelper::Redirect("/Admin/PlaceList.php");       
    }
    
    DbConnector::Disconnect();

?>

<html>
    
    <body>        
    <?= $place->name ?><br>
    
    <form action="Place.php" method="post">
        
        <input type="hidden" id="_ispostback" name="_ispostback" value="anyvalue" />
        <input type="hidden" id="ID" name="ID" value="<?= $place->id ?>" />
        
        <label for="Name">Name:</label> <input type="text" id="Name" name="Name" value="<?= $place->name ?>" /><br>
        <label for="Name">Description:</label> <textarea id="Description" name="Description" value="<?= $place->description ?>"></textarea><br>
        <label for="Name">Address:</label> <textarea id="Address" name="Address" value="<?= $place->address ?>"></textarea><br>
        <label for="Name">Direction:</label> <textarea id="Direction" name="Direction" value="<?= $place->direction ?>"></textarea><br>
        <label for="Name">Featured:</label> <input type="CHECKBOX" id="Featured" name="Featured" value="<?= $place->featured ?>" /><br>        
        <label for="Name">Lat.:</label> <input type="text" id="Lat" name="Lat" value="<?= $place->lat ?>" /><br>
        <label for="Name">Lan.:</label> <input type="text" id="Lon" name="Lon" value="<?= $place->lon ?>" /><br>
        <label for="Name">Tag:</label> <input type="text" id="Tag" name="Tag" value="<?= $place->tag ?>" /><br>
        
        <input type="SUBMIT" value="Submit" />
    </form>
    
    </body>
    
</html>